package com.three.system.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.three.core.entity.User;
import com.three.system.mapper.UserMapper;
import com.three.system.service.UserService;
import com.three.core.vo.R;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public R<User> getByName(String userName) {
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_name",userName);
        User user = userMapper.selectOne(queryWrapper);
        user.setLoginDate(LocalDateTime.now());
        if(user==null){
            return new R<>(500,"账号不存在",null);
        }
        if(user.getStatus().equals("1")){
            return new R<>(500,"账号异常",null);
        }
        if(user.getDelFlag().equals("1")){
            return new R<>(500,"账号已注销",null);
        }
        return new R<User>(200,"登录成功",user);
    }

    @Override
    public R<List<User>> selectAll() {
        return new R<List<User>>(200, "查询成功", userMapper.selectList(null));
    }


}
